#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int totalFruit(vector<int>& fruits) {

        int mp[100001] = { 0 };
        int len = 0;
        for (int right = 0, left = 0, kinds = 0; right < fruits.size(); right++)
        {
            if (mp[fruits[right]] == 0)kinds++;
            mp[fruits[right]]++;
            if (kinds > 2)
            {

                mp[fruits[left]]--;

                if (mp[fruits[left]] == 0)
                    kinds--;
                left++;
            }
            len = max(len, right - left + 1);
        }
        return len;
    }
};